﻿#include <iostream>
#include <string>

using namespace std;
// 装饰着模式的结构:  1. 装饰者和被装饰者都继承自同一个接口，因为装饰者是对被装饰者的一个强化
//                   2. 装饰者应该定义一个统一的接口，便于拓展装饰者的功能
class AbCommonInterface
{
protected:
  string m_name;

public:
  AbCommonInterface() = default;
  AbCommonInterface(const string &name) : m_name(name) {}
  virtual ~AbCommonInterface() = default;
  virtual void show() = 0;
};
class Decorator : public AbCommonInterface
{
public:
  using AbCommonInterface::AbCommonInterface;
  void show() override
  {
    cout << "我是Decorator对象的最原始方法" << endl;
  }
};
class AbGarnisher : public AbCommonInterface
{
protected:
  AbCommonInterface *mptr_decorator = nullptr;

public:
  virtual void show() = 0;
  virtual void enchantment(AbCommonInterface *decorator)
  {
    mptr_decorator = decorator;
  }
};
class Garnisher01 : public AbGarnisher
{
public:
  void show() override
  {
    cout << "我是装饰者对象1,我对被装饰者Decorator的功能进行了功能拓展1111" << endl;
    mptr_decorator->show();
  }
};
class Garnisher02 : public AbGarnisher
{
public:
  void show() override
  {
    cout << "我是装饰者对象2,我对被装饰者Decorator的功能进行了功能拓展2222" << endl;
    mptr_decorator->show();
  }
};
int main()
{
  AbCommonInterface *decorator = new Decorator("被装饰者张三丰");
  Garnisher01 *garnisher01 = new Garnisher01();
  Garnisher02 *garnisher02 = new Garnisher02();
  garnisher01->enchantment(decorator);
  garnisher02->enchantment(garnisher01);
  garnisher02->show();
  return 0;
}